/***************************************************************************
                          mstl.h  -  Mini-STL library
                             -------------------
    begin                : Mon May 6 2002
    copyright            : (C) 2002 by Michiel Visser
    email                :
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

//---------------------------------------------------------------------------
#ifndef __MSTL_DBG_H__
#define __MSTL_DBG_H__
//---------------------------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef __MINGW32__
#include <windows.h>
#endif

#define MALLOC_VERBOSE_GC
// { ------ configuration --------
#ifdef DEBUG
#define IFDEBUG(x) x
#ifndef _DEBUG_ENABLE
#define _DEBUG_ENABLE 1
#endif
//#define TRACE_IN_MEMORY

#define _IF_STOP_ON_ASSERT(y,n) y
///#define MALLOC_COUNT // counts the different types of memory allocation
#define MALLOC_BOUNDARY_TEST // adds and tests a boundary round variable memory allocations
#define MALLOC_FREE_TEST // tests whether freeing memblock is ok
#define MALLOC_WIPE // this increases the likelyhood a program will generate an error on usage of invalidated memory
#define UNITALLOCATOR_POINTERVALIDITY_TEST
//#define UNITALLOCATOR_PAINTCOMPLETENESS_TEST
#define UNITALLOCATOR_ASSURESINGLETHREAD_TEST
#define UNITALLOCATOR_CHAIN_CHECK
//#define MALLOC_VERBOSE_GC
//#define VERBOSE_OLT // Object LifeTime
#define IFDEBUGDEEP(x) //x
#define IF_SHOW_UNITALLOCATOR_CHAIN(x) //x

#else
#define IFDEBUG(x)
#define IFDEBUGDEEP(x)
#define IF_SHOW_UNITALLOCATOR_CHAIN(x)
#endif
// } ------------------------

#define _IF_AUTOFLUSH(yes,no)   yes
#ifdef __MINGW32__
#define _FLUSH                  fflush(_DEBUG_STREAM);FlushFileBuffers ((HANDLE) _get_osfhandle (fileno (_DEBUG_STREAM)));
#endif
#define _IF_ANSI(yes,no)        no
#define _ERROR_HANDLING _DIV_BY_ZERO
#include <handy2.h>

#ifdef UNITALLOCATOR_CHAIN_CHECK
#define IF_UNITALLOCATOR_CHAIN_CHECK(x) x
#else
#define IF_UNITALLOCATOR_CHAIN_CHECK(x)
#endif
#ifdef MALLOC_COUNT
extern struct MCount { int variable; int block; int deletionCandidate; } mcounts;
#endif
#ifdef VERBOSE_OLT
#define IF_VERBOSE_OLT(x) x
#else
#define IF_VERBOSE_OLT(x)
#endif

IFDEBUG(extern int dbgvars[16];)

#ifdef TRACE_IN_MEMORY
typedef struct { short id; short line;} dbg_lines_struct;
extern dbg_lines_struct dbg_lines[16];
extern int dbg_li;
#define TRC(ID) { dbg_lines[dbg_li].id=ID; dbg_lines[dbg_li].line=__LINE__; dbg_li=(dbg_li+1)&15;dbg_lines[dbg_li].id=11111; } 
#endif

#endif /* __MSTL_DBG_H__ */

